/*
 * @Author: cl
 * @Description: 插件配置
 * @Date: 2023-05-17 16:31:32
 * @LastEditTime: 2023-07-05 16:23:30
 * @FilePath: \vue3scaffold\vite\plugins\index.ts
 * @LastEditors: chenli chenli@kcwl.com
 */

import vue from "@vitejs/plugin-vue";
import { Plugin } from "vite";
import setMock from './mock';
import topLevelAwait from 'vite-plugin-top-level-await'

export default function setupPlugins(
  isBuild: boolean,
  env: ViteEnv
) {
  const plugins: Plugin[] = [vue()];
  plugins.push(setMock(isBuild));
  plugins.push(topLevelAwait({
    // The export name of top-level await promise for each chunk module
    promiseExportName: '__tla',
    // The function to generate import names of top-level await promise in each chunk module
    promiseImportName: i => `__tla_${i}`
  }));
  return plugins;
}
